import { request } from 'umi';
import type {LendLogItem} from "@/pages/LendLogs/data";

export async function queryLendLog(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: LendLogItem[];
    total: number;
    success?: boolean;
    status: string;
    message: string;
  }>('/api/lendLog', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {})
  });
}

// 根据LendLogId查询还款记录
export async function queryLendPayBackLog(
  params: {
    lendId: any
  },
  options?: Record<string, any>,
) {
  return request<{
    data: LendLogItem[];
    total?: number;
    success?: boolean;
    status?: string;
  }>('/api/lendLog/paybackLog', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {})
  });
}

// 登记还钱
export async function addLendPaybackLog(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/lendLog/paybackLog', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 修改流水
export async function updateLendLog(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/lendLog', {
    data,
    method: 'PUT',
    ...(options || {}),
  });
}

// 删除流水
export async function deleteLendLog(data: { key: number }, options?: Record<string, any>) {
  return request<Record<string, any>>('/api/lendLog', {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}

// 删除流水中的还款记录
export async function deleteLendPaybackLog(data: { key: number, lendId: number }, options?: Record<string, any>) {
  return request<Record<string, any>>('/api/lendLog/paybackLog', {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}
